import Mock from 'mockjs'
import {ProductInterface} from '../types/product.d'

let template = {
    "list|10" : [
        {
            "id|+1" : 0,
            "title" : "@ctitle(2,4)",
            "img" : "@image(100x100,@color,@city)",
            "price|1-100" : 1
        }
    ]
}

let data = Mock.mock(template)

Mock.mock('/api/list','get',() => {
    return data
})


Mock.mock('/api/detail','get',(config:any) => {
    let {id} = JSON.parse(config.body);
    let target = data.list.find((item:ProductInterface) => item.id == id);
    return target
})